package com.elai.baseconfig.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.elai.common.annotation.Log;
import com.elai.common.core.controller.BaseController;
import com.elai.common.core.domain.AjaxResult;
import com.elai.common.enums.BusinessType;
import com.elai.baseconfig.domain.ChannelConfig;
import com.elai.baseconfig.service.IChannelConfigService;
import com.elai.common.utils.poi.ExcelUtil;
import com.elai.common.core.page.TableDataInfo;

/**
 * 全局触达配置Controller
 * 
 * @author elai
 * @date 2021-08-15
 */
@RestController
@RequestMapping("/baseconfig/config")
public class ChannelConfigController extends BaseController
{
    @Autowired
    private IChannelConfigService channelConfigService;

    /**
     * 查询全局触达配置列表
     */
    @PreAuthorize("@ss.hasPermi('baseconfig:config:list')")
    @GetMapping("/list")
    public TableDataInfo list(ChannelConfig channelConfig)
    {
        startPage();
        List<ChannelConfig> list = channelConfigService.selectChannelConfigList(channelConfig);
        return getDataTable(list);
    }

    /**
     * 导出全局触达配置列表
     */
    @PreAuthorize("@ss.hasPermi('baseconfig:config:export')")
    @Log(title = "全局触达配置", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ChannelConfig channelConfig)
    {
        List<ChannelConfig> list = channelConfigService.selectChannelConfigList(channelConfig);
        ExcelUtil<ChannelConfig> util = new ExcelUtil<ChannelConfig>(ChannelConfig.class);
        return util.exportExcel(list, "全局触达配置数据");
    }

    /**
     * 获取全局触达配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('baseconfig:config:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(channelConfigService.selectChannelConfigById(id));
    }

    /**
     * 新增全局触达配置
     */
    @PreAuthorize("@ss.hasPermi('baseconfig:config:add')")
    @Log(title = "全局触达配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ChannelConfig channelConfig)
    {
        return toAjax(channelConfigService.insertChannelConfig(channelConfig));
    }

    /**
     * 修改全局触达配置
     */
    @PreAuthorize("@ss.hasPermi('baseconfig:config:edit')")
    @Log(title = "全局触达配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ChannelConfig channelConfig)
    {
        return toAjax(channelConfigService.updateChannelConfig(channelConfig));
    }

    /**
     * 删除全局触达配置
     */
    @PreAuthorize("@ss.hasPermi('baseconfig:config:remove')")
    @Log(title = "全局触达配置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(channelConfigService.deleteChannelConfigByIds(ids));
    }
}
